package com.itbaizhan.controller;

import com.itbaizhan.entity.ActorsRecord;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class OutputController {


    @Autowired
    ChatModel chatModel;

    /**
     * 结构化输出 对象
     */
    @GetMapping("/chat")
    public Map<String, Object> chat(){
        // 生成5部电影的目录，李连杰
//        ActorsRecord entity = ChatClient.create(chatModel)
//                .prompt()
//                // 提示词
//                .user(u -> u.text("生成5部电影的目录{actor}").param("actor", "李连杰"))
//                .call()
//                .entity(ActorsRecord.class);
//        return entity;

   /*     List<ActorsRecord> actorsRecords = ChatClient.create(chatModel)
                .prompt()
                .user("给李连杰生成5部电影的目录")
                .call()
                .entity(new ParameterizedTypeReference<List<ActorsRecord>>() {
                });
*/


        Map<String, Object> subject = ChatClient.create(chatModel)
                .prompt()
                .user(u -> u.text("请给我提供一份{subject}列表").param("subject", "关键字'number'1到9的数字数组"))
                .call()
                .entity(new ParameterizedTypeReference<Map<String, Object>>() {
                });


        return subject;


    }



}
